<template>
  <div class="page-container">
    <div class="info-container">
      <div class="info-container_body">
        <el-form ref="refFrom" label-position="top" :model="form.model" class="demo">
          <div class="form-section">
            <div class="form-section_title">元数据删除时限设置</div>
            <el-form-item label="时限（小时）">
              <el-input class="w-220" type="number" v-model="form.model.time"></el-input>
            </el-form-item>
            <div class="form-section_title">天起始设置</div>
            <el-form-item label="缺省12:00，即12时起至次日12时止">
              <el-input class="w-220" type="number" v-model="form.model.time"></el-input>
            </el-form-item>
            <!-- <div class="form-section_title">终端信息上报频率设置</div>
            <el-form-item label="缺省1次/分钟">
              <el-input class="w-220" type="number" v-model="form.model.time"></el-input>
            </el-form-item> -->
            <div class="form-section_title">入住判断</div>
            <el-form-item label="供氧终端最小在线时长（小时）">
              <el-input class="w-220" type="number" v-model="form.model.time"></el-input>
            </el-form-item>
            <div class="form-section_title">结账日</div>
            <el-form-item label="缺省3号">
              <el-input class="w-220" type="number" v-model="form.model.time"></el-input>
            </el-form-item>
            <!--            <div class="form-section_title">报警通道设置</div>
            <el-form-item label="推送方式">
              <DictSelect dict="device_status" v-model="form.model.status" placeholder="状态" clearable />
            </el-form-item>-->
          </div>
        </el-form>
      </div>
      <div class="info-container_footer">
        <el-button @click="handleCancel">取消</el-button>
        <el-button type="primary" @click="handleSubmit">确定</el-button>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { addStation, updateStation } from '@/api/station/index';
import { StationForm, defaultStationModel } from '@/api/station/types';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;

const form = reactive({
  model: defaultStationModel()
});
const loading = ref(false);
const refFrom = ref<ElFormInstance>();

/** 取消 */
const handleCancel = () => {
  // proxy?.$tab.closeOpenPage()
  proxy?.$tab.closePage();
};
/** 确认 */
const handleSubmit = async () => {
  if (!refFrom.value) return;
  refFrom.value.validate((valid, fields) => {
    if (valid) {
      requestSubmit();
    } else {
      console.log('error submit!', fields);
    }
  });
};
const getInfo = async () => {
  loading.value = true;
  let res = { code: 200, data: {}, msg: '' }; //await getStation(id)
  loading.value = false;
  if (res.code == 200) {
    // form.model = res.data
  } else {
    proxy?.$modal.msgError(res.msg || '信息获取失败！');
  }
};
const requestSubmit = async () => {
  loading.value = true;
  let res = await updateStation(form.model as StationForm);
  loading.value = false;
  if (res.code == 200) {
    proxy?.$modal.msgSuccess('保存成功！');
  } else {
    proxy?.$modal.msgError(res.msg || '保存失败！');
  }
};

getInfo();
onMounted(() => {});
</script>
